package com.gem.growingtree.fragment;



import java.util.ArrayList;

import com.gem.growingtree.activity.R;

import android.content.res.Resources;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;


public class CommunicationCicle extends Fragment{
	Resources resources;
	private ViewPager mPager;
	private ArrayList<Fragment> fragmentsList;
	private TextView tvClassCircle, tvSchoolCircle;

	private int currIndex = 0;
	public final static int num = 2 ; 
	Fragment classCicle;
	Fragment schoolCircle;
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		View view = inflater.inflate(R.layout.lay3,container,false);
		
		resources = getResources();
	//	InitWidth(view);
		InitTextView(view);
		InitViewPager(view);
		return view;
		
		
	}

	

	private void InitViewPager(View parentView) {
		// TODO Auto-generated method stub
		
			mPager = (ViewPager) parentView.findViewById(R.id.vPager);
			fragmentsList = new ArrayList<Fragment>();

			classCicle = new ClassCicle();
			schoolCircle = new SchoolCircle();

			fragmentsList.add(classCicle);
			fragmentsList.add(schoolCircle);

			mPager.setAdapter(new MyFragmentPagerAdapter(getChildFragmentManager(), fragmentsList));
			mPager.setOnPageChangeListener(new MyOnPageChangeListener());
			mPager.setCurrentItem(0);
			tvClassCircle.setTextColor(resources.getColor(R.color.white));


		
	}



/*	private void InitWidth(View parentView) {
		// TODO Auto-generated method stub
		ivBottomLine = (ImageView) parentView.findViewById(R.id.iv_bottom_line);
		bottomLineWidth = ivBottomLine.getLayoutParams().width;
		DisplayMetrics dm = new DisplayMetrics();
		getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
		int screenW = dm.widthPixels;
		offset = (int) ((screenW / num - bottomLineWidth) / 2);
		int avg = (int) (screenW / num);
		position_one = avg + offset;
	
	}*/



	private void InitTextView(View parentView) {
		
		tvClassCircle= (TextView) parentView.findViewById(R.id.tv_class_circle);
		tvSchoolCircle = (TextView) parentView.findViewById(R.id.tv_school_circle);

		tvClassCircle.setOnClickListener(new MyOnClickListener(0));
		tvSchoolCircle.setOnClickListener(new MyOnClickListener(1));
		
	}
	public class MyOnClickListener implements View.OnClickListener {
		private int index = 0;

		public MyOnClickListener(int i) {
			index = i;
		}

		@Override
		public void onClick(View v) {
			mPager.setCurrentItem(index);
		}
	};
       
	public class MyOnPageChangeListener implements OnPageChangeListener {

		@Override
		public void onPageSelected(int arg0) {
			
			switch (arg0) {
			case 0:
				if (currIndex == 1) {
					tvClassCircle.setTextColor(resources.getColor(R.color.white));
				} 
				tvSchoolCircle.setTextColor(resources.getColor(R.color.default_white));
				break;
			case 1:
				if (currIndex == 0) {
					tvSchoolCircle.setTextColor(resources.getColor(R.color.white));
				} 
				tvClassCircle.setTextColor(resources.getColor(R.color.default_white));
				break;
			}
			currIndex = arg0;
		}

		@Override
		public void onPageScrolled(int arg0, float arg1, int arg2) {
		}

		@Override
		public void onPageScrollStateChanged(int arg0) {
		}
	}

	
	
	
	
	
	
    }

	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	


//	public final static int num = 4 ; 
//    Fragment homeFragment;
//    Fragment personFragment;
//    Fragment sorttypeFragment;
//    private FragmentManager fragmentManager;
//    private FragmentTransaction transaction;
//    private RadioGroup radioGroup;
//    
//    @Override
//    public void onCreate(Bundle savedInstanceState) {
//    	// TODO Auto-generated method stub
//    	super.onCreate(savedInstanceState);
//    	
//    }
//    
//    @Override
//    public View onCreateView(LayoutInflater inflater, ViewGroup container,
//    		Bundle savedInstanceState) {
//    	View view=inflater.inflate(R.layout.lay3, container, false);
//    	
//    	fragmentManager = getChildFragmentManager();
//    	 radioGroup = (RadioGroup)getActivity().findViewById(R.id.rg_radioGroup);
//         ((RadioButton)radioGroup.findViewById(R.id.rb0)).setChecked(true);
//        
//         transaction = fragmentManager.beginTransaction();
//		
//         Fragment fragment = new FriendCicle();
//         transaction.replace(R.id.content, fragment);
//         transaction.commit();
//         
//         radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener()
//         {
//
//			@Override
//			public void onCheckedChanged(RadioGroup group, int checkedId) {
//				// TODO Auto-generated method stub
//				switch (checkedId) {
//				case R.id.rb0:
//					transaction = fragmentManager.beginTransaction();
//	                Fragment friendCicle = new FriendCicle();
//	                transaction.replace(R.id.content,friendCicle);
//	                transaction.commit();
//					break;
//				case R.id.rb1:
//					transaction = fragmentManager.beginTransaction();
//	                Fragment schoolCircle = new SchoolCircle();
//	                transaction.replace(R.id.content, schoolCircle);
//	                transaction.commit();
//					break;
//				
//            	}	
//			}
//        	 
//         });
//         return view;
//    	
//    	
//    	
//    }
// 
    
    


